package cn.xinzhi.servlet;

import cn.xinzhi.Util.KeyDaoUtil;
import cn.xinzhi.dao.Impl.Yh_loginDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "AlterServlet")
public class AlterServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        String pwd =request.getParameter("xpassword");
        String pwdjm1=new KeyDaoUtil(pwd).get32();
        //System.out.println(pwdjm1);


        String  pwd1=request.getParameter("jpassword");
        String pwdjm2=new KeyDaoUtil(pwd1).get32();
//        System.out.println(pwdjm2);
        Yh_loginDaoImpl yh_loginDao=new Yh_loginDaoImpl();
        int count=yh_loginDao.alterpassword(pwdjm1,pwdjm2);
        if (count!=0){
            response.sendRedirect("login.jsp");
        }else {
            response.sendRedirect("pass.jsp");
        }
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
